<template>
  <el-dialog
    :title="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"
    :close-on-click-modal="false"
    :visible.sync="visible"
    class="JADP-dialog JADP-dialog_center"
    lock-scroll
    width="1200px"
  >
    <el-row :gutter="15" class="">
      <el-form
        ref="elForm"
        :model="dataForm"
        :rules="rules"
        size="small"
        label-width="80px"
        label-position="right"
        :disabled="!!isDetail"
      >
        <el-col :span="24">
          <el-form-item label="问题标题" prop="title">
            <el-input
              v-model="dataForm.title"
              placeholder="请输入"
              clearable
              :style="{ width: '100%' }"
              readonly
            >
            </el-input>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item label="问题内容" prop="content">
            <JADP-Quill
              v-model="dataForm.content"
              placeholder="请输入内容..."
              disable
            >
            </JADP-Quill>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item label="问题答复" prop="auswer">
            <JADP-Quill v-model="dataForm.auswer" placeholder="请输入内容...">
            </JADP-Quill>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail"
        >确 定</el-button
      >
    </span>
  </el-dialog>
</template>
<script>
import request from "@/utils/request";
import { getDictionaryDataSelector } from "@/api/systemData/dictionary";
import { previewDataInterface } from "@/api/systemData/dataInterface";
import ExportBox from "./ExportBox";
export default {
  components: { ExportBox },
  props: [],
  data() {
    return {
      loading: false,
      visible: false,
      isDetail: false,
      activeName: "",
      dataForm: {
        title: undefined,
        content: undefined,
        auswer: undefined,
        clazzid: undefined,
        courseid: undefined,
        userid: undefined,
        coursename: undefined,
        clazzname: undefined,
        questioner: undefined,
        creatoruserid: "",
        creatortime: "",
        lastmodifyuserid: "",
        lastmodifytime: "",
        answerstatus: "未回复",
        organizeId:""
      },
      rules: {},
      answerstatusOptions: [
        { fullName: "已回复", id: "1" },
        { fullName: "未回复", id: "2" }
      ]
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    init(id, isDetail) {
      this.dataForm.id = id || 0;
      this.visible = true;
      this.isDetail = isDetail || false;
      this.$nextTick(() => {
        this.$refs["elForm"].resetFields();
        if (this.dataForm.id) {
          this.loading = true;
          request({
            url:
              "/api/questionAnswer/Xy_ks_question_answer/" + this.dataForm.id,
            method: "get"
          }).then(res => {
            this.dataForm = res.data;
            this.loading = false;
          });
        }
      });
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs["elForm"].validate(valid => {
        if (valid) {
          this.dataForm.organizeId= this.$store.getters.organizeId;
          if (!this.dataForm.id) {
            request({
              url: `/api/questionAnswer/Xy_ks_question_answer`,
              method: "post",
              data: this.dataForm
            }).then(res => {
              this.$message({
                message: res.msg,
                type: "success",
                duration: 1000,
                onClose: () => {
                  (this.visible = false), this.$emit("refresh", true);
                }
              });
            });
          } else {
            if (this.dataForm.auswer) {
              this.dataForm.answerstatus = "已回复";
            }
            request({
              url:
                "/api/questionAnswer/Xy_ks_question_answer/" + this.dataForm.id,
              method: "PUT",
              data: this.dataForm
            }).then(res => {
              this.$message({
                message: res.msg,
                type: "success",
                duration: 1000,
                onClose: () => {
                  this.visible = false;
                  this.$emit("refresh", true);
                }
              });
            });
          }
        }
      });
    }
  }
};
</script>
